var url = require('../../config.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    hiddenHeader: true,
    hiddenMain: true,
    index_text: '',
    update_time: '',
    songList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '正在加载',
    })

    console.log(options)
    var index = options.index;
    var index_text = '';
    switch(index){
      case '3': index_text = '巅峰榜·欧美'; break;
      case '4': index_text = '巅峰榜·流行指数'; break;
      case '5': index_text = '巅峰榜·内地'; break;
      case '6': index_text = '巅峰榜·港台'; break;
      case '16': index_text = '巅峰榜·韩国'; break;
      case '17': index_text = '巅峰榜·日本'; break;
      case '26': index_text = '巅峰榜·热歌'; break;
      case '27': index_text = '巅峰榜·新歌'; break;
      case '28': index_text = '巅峰榜·网络歌曲'; break;
      case '32': index_text = '巅峰榜·腾讯音乐人原创榜'; break;
      case '36': index_text = '巅峰榜·K歌金曲'; break;
    };
    this.setData({
      index_text: index_text
    });

    wx.request({
      url: url.url_list,
      data: {
        topid: index
      },
      success: res => {
        console.log(res)
        if (res.data.showapi_res_body.ret_code == 0) {
          var update_time = res.data.showapi_res_body.pagebean.update_time ? res.data.showapi_res_body.pagebean.update_time : new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate();
          this.setData({
            update_time: update_time,
            songList: res.data.showapi_res_body.pagebean.songlist,
            hiddenHeader: false,
            hiddenMain: false
          });
        } else {
          console.log(res.data.showapi_res_body.remark);
        };
      },
      fail: err => {
        console.log(err)
        wx.showToast({
          title: '请求失败',
          icon: 'none'
        })
      },
      complete: opt => {
        wx.hideLoading()
        
      }
    })

  },
  play: function (e) {
    // 由于权限限制，请求的音乐无法播放，故这里只是个例子
    const backgroundAudioManager = wx.getBackgroundAudioManager()

    backgroundAudioManager.title = '此时此刻'
    backgroundAudioManager.epname = '此时此刻'
    backgroundAudioManager.singer = '许巍'
    backgroundAudioManager.coverImgUrl = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'
    backgroundAudioManager.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})